
package org.sunspotworld.demo;


public class RhythmMatrix extends DecisionMatrix
{
    private static final int size = 8;
    
    public RhythmMatrix()
    {
        super(size);
        initializeRoleMatrix();
        initializeAVMatrices();
    }
    
    
    /**
     * Set up the highest/lowest valence/arousal tables that determine the 
     * reactions to changing AV values.
     */
    private void initializeAVMatrices()
    {
        //Rhythm is really only affected by arousal, with high arousal tending
        // towards both shorter notes and mixed rhythms, and low arousal tending
        // towards longer notes that are mostly the same length.
        
        if(SunSpotAudio.m_role == SunSpotAudio.role_bass)
        {
            m_lowestArousal = new float[][]{{1, 1, 1, 5, 5, 20, 20, 5},
                                            {1, 1, 1, 5, 5, 20, 20, 5},
                                            {1, 1, 1, 5, 5, 20, 20, 5},
                                            {1, 1, 1, 5, 5, 20, 20, 5},
                                            {1, 1, 1, 5, 5, 20, 20, 5},
                                            {1, 1, 1, 5, 5, 20, 20, 5},
                                            {1, 1, 1, 5, 5, 20, 20, 5},
                                            {1, 1, 1, 5, 5, 20, 20, 5}};
            m_highestArousal = new float[][]{{20, 15, 15, 7, 2, 1, 1, 1},
                                            {20, 15, 20, 7, 2, 1, 1, 1},
                                            {20, 15, 20, 7, 2, 1, 1, 1},
                                            {20, 20, 20, 7, 2, 1, 1, 1},
                                            {20, 20, 20, 7, 2, 1, 1, 1},
                                            {20, 20, 20, 7, 2, 1, 1, 0},
                                            {15, 20, 20, 7, 2, 1, 0, 0},
                                            {15, 15, 20, 7, 2, 0, 0, 0}};
        }
        if(SunSpotAudio.m_role == SunSpotAudio.role_melody)
        {
            m_lowestArousal = new float[][]{{1, 1, 1, 1, 5, 20, 5, 15},
                                            {1, 1, 1, 1, 5, 20, 5, 15},
                                            {1, 1, 1, 1, 5, 20, 5, 15},
                                            {1, 1, 1, 1, 5, 20, 5, 15},
                                            {1, 1, 1, 1, 5, 20, 5, 15},
                                            {1, 1, 1, 1, 5, 20, 5, 15},
                                            {1, 1, 1, 1, 5, 20, 5, 15},
                                            {1, 1, 1, 1, 5, 20, 5, 15}};
            m_highestArousal = new float[][]{{25, 15, 15, 5, 2, 1, 1, 1},
                                            {25, 15, 10, 5, 2, 1, 1, 1},
                                            {25, 15, 10, 5, 2, 1, 1, 1},
                                            {25, 20, 10, 5, 2, 1, 1, 1},
                                            {25, 20, 10, 5, 2, 1, 1, 1},
                                            {25, 20, 10, 5, 2, 1, 1, 0},
                                            {15, 20, 10, 5, 2, 1, 0, 0},
                                            {15, 15, 10, 5, 1, 0, 0, 0}};
        }
        else
        {
            m_lowestArousal = new float[][]{{1, 1, 1, 2, 7, 20, 40, 50},
                                            {1, 1, 1, 2, 7, 20, 40, 50},
                                            {1, 1, 1, 2, 7, 20, 40, 50},
                                            {1, 1, 1, 2, 7, 20, 40, 50},
                                            {1, 1, 1, 2, 7, 20, 40, 50},
                                            {1, 1, 1, 2, 7, 20, 40, 50},
                                            {1, 1, 1, 2, 7, 20, 40, 50},
                                            {1, 1, 1, 2, 7, 20, 40, 50}};
            m_highestArousal = new float[][]{{50, 40, 40, 7, 2, 1, 1, 1},
                                            {50, 40, 50, 7, 2, 1, 1, 1},
                                            {50, 40, 50, 7, 2, 1, 1, 1},
                                            {50, 50, 50, 7, 2, 1, 1, 1},
                                            {50, 50, 50, 7, 2, 1, 1, 1},
                                            {50, 50, 50, 7, 2, 1, 1, 0},
                                            {40, 50, 50, 7, 2, 1, 0, 0},
                                            {40, 40, 50, 7, 2, 0, 0, 0}};
        }
        m_lowestValence = new float[][]{{4, 4, 4, 4, 5, 5, 5, 5},
                                        {4, 4, 4, 4, 5, 5, 5, 5},
                                        {4, 4, 4, 4, 5, 5, 5, 5},
                                        {4, 4, 4, 4, 5, 5, 5, 5},
                                        {4, 4, 4, 4, 5, 5, 5, 5},
                                        {4, 4, 4, 4, 5, 5, 5, 5},
                                        {4, 4, 4, 4, 5, 5, 5, 5},
                                        {4, 4, 4, 4, 5, 5, 5, 5}};
        m_highestValence = new float[][]{{5, 5, 5, 5, 4, 4, 4, 4},
                                        {5, 5, 5, 5, 4, 4, 4, 4},
                                        {5, 5, 5, 5, 4, 4, 4, 4},
                                        {5, 5, 5, 5, 4, 4, 4, 4},
                                        {5, 5, 5, 5, 4, 4, 4, 4},
                                        {5, 5, 5, 5, 4, 4, 4, 4},
                                        {5, 5, 5, 5, 4, 4, 4, 4},
                                        {5, 5, 5, 5, 4, 4, 4, 4}};
    }
    
    private void initializeRoleMatrix()
    {
        if(SunSpotAudio.m_role == SunSpotAudio.role_harmony)
        {
            for(int i = 0; i < m_size; i++)
            {
                for(int j = 0; j < m_size; j++)
                {
                    if(j == 7)
                    {
                        m_roleMatrix[i][j] = 4;
                    }
                    else if(j >= 4)
                    {
                        //Favor longish notes
                        m_roleMatrix[i][j] = 50;
                    }
                    else if(j >= 2)
                    {
                        m_roleMatrix[i][j] = 10;
                    }
                    else
                    {
                        m_roleMatrix[i][j] = 1;
                    }
                }
            }
        }
        else if(SunSpotAudio.m_role == SunSpotAudio.role_bass)
        {
            for(int i = 0; i < m_size; i++)
            {
                for(int j = 0; j < m_size; j++)
                {
                    //testing bass role through transitions only
                    m_roleMatrix[i][j] = 1;
                    /*if(j >= 1 && j <= 3)
                    {
                        //Favor eighth notes and quarter notes
                        m_roleMatrix[i][j] = 50;
                    }
                    else if(j >= 4 && j <= 5)
                    {
                        m_roleMatrix[i][j] = 10;
                    }
                    else
                    {
                        m_roleMatrix[i][j] = 1;
                    }*/
                }
            }  
        }
        else if(SunSpotAudio.m_role == SunSpotAudio.role_percussion)
        {
            for(int i = 0; i < m_size; i++)
            {
                for(int j = 0; j < m_size; j++)
                {
                    if(j == 0)
                    {
                        //Favor fast notes
                        m_roleMatrix[i][j] = 150;
                    }
                    else if(j < 3)
                    {
                        m_roleMatrix[i][j] = 30;
                    }
                    else if(j == 3)
                    {
                        m_roleMatrix[i][j] = 3;
                    }
                    else
                    {
                        m_roleMatrix[i][j] = 1;
                    }
                }
            }
        }
        else //if(SunSpotAudio.m_role == SunSpotAudio.role_melody)
        {
            for(int i = 0; i < m_size; i++)
            {
                for(int j = 0; j < m_size; j++)
                {
                    if(j == 1)
                    {
                        //Favor fast notes
                        m_roleMatrix[i][j] = 40;
                    }
                    else if(j < 3)
                    {
                        m_roleMatrix[i][j] = 10;
                    }
                    else
                    {
                        m_roleMatrix[i][j] = 1;
                    }
                }
            }
        }
    }
}
